        <!DOCTYPE html>
        <html>
        <head>
                <meta charset="utf-8">
        <title>AxisAlignedBox class / box2d Library / Dart Documentation</title>
        <link rel="stylesheet" type="text/css"
            href="../styles.css">
        <link href="http://fonts.googleapis.com/css?family=Open+Sans:400,600,700,800" rel="stylesheet" type="text/css">
        <link rel="shortcut icon" href="../favicon.ico">
        
        </head>
        <body data-library="box2d" data-type="AxisAlignedBox">
        <div class="page">
        <div class="header">
          <a href="../index.html"><div class="logo"></div></a>
          <a href="../index.html">Dart Documentation</a>
         &rsaquo; <a href="../box2d.html">box2d</a> &rsaquo; <a href="../box2d/AxisAlignedBox.html">AxisAlignedBox</a>        <div id="search-box">
          <input type="search" name="q" id="q" autocomplete="off"
              class="search-input" placeholder="Search API">
        </div>
        
      </div>
      <div class="drop-down" id="drop-down"></div>
      
        <div class="nav">
        
</div>
<div class="content">
        <h2><strong>AxisAlignedBox</strong>
          class
        </h2>
        
<button id="show-inherited" class="show-inherited">Hide inherited</button>
<div class="doc">
<pre class="source">
class AxisAlignedBox {
 /** Bottom left vertex of bounding box. */
 vec2 lowerBound;

 /** Top right vertex of bounding box. */
 vec2 upperBound;

 /**
  * Constructs a new box with the given lower and upper bounds. If no bounds
  * are specified, constructs the box with both bounds at the origin.
  */
 AxisAlignedBox([this.lowerBound = null, this.upperBound = null]) {
   if (lowerBound == null) lowerBound = new vec2.zero();
   if (upperBound == null) upperBound = new vec2.zero();
 }

 /**
  * Sets this box to be a combination of the two given boxes.
  * The combination is determined by picking and choosing the lowest x and y
  * values from the lowerBounds to form a new lower bound and picking and
  * choosing the largest x and y values from the upperBounds to form a new
  * upperBound.
  */
 void setFromCombination(AxisAlignedBox boxOne, AxisAlignedBox boxTwo) {
   lowerBound.x = math.min(boxOne.lowerBound.x, boxTwo.lowerBound.x);
   lowerBound.y = math.min(boxOne.lowerBound.y, boxTwo.lowerBound.y);
   upperBound.x = math.max(boxOne.upperBound.x, boxTwo.upperBound.x);
   upperBound.y = math.max(boxOne.upperBound.y, boxTwo.upperBound.y);
 }

 /** Sets the bounds to the given values. */
 AxisAlignedBox setBounds(vec2 lower, vec2 upper) {
   lowerBound.copyFrom(lower);
   upperBound.copyFrom(upper);
   return this;
 }

 /** Returns true if the given box overlaps with this box. */
 static bool testOverlap(AxisAlignedBox a, AxisAlignedBox b) =&gt;
   !((b.lowerBound.x &gt; a.upperBound.x || b.lowerBound.y &gt; a.upperBound.y) ||
     (a.lowerBound.x &gt; b.upperBound.x || a.lowerBound.y &gt; b.upperBound.y));

 /**
  * Returns true if the lower bound is strictly less than the upper bound and
  * both bounds are themselves valid (Vector.isValid() returns true).
  */
 bool isValid() =&gt; !lowerBound.isInfinite &amp;&amp; !upperBound.isInfinite &amp;&amp;
                   !lowerBound.isNaN &amp;&amp; !upperBound.isNaN &amp;&amp;
                   lowerBound.x &lt; upperBound.x &amp;&amp; lowerBound.y &lt; upperBound.y;

 /** Returns the center of this box. */
 vec2 get center =&gt; (lowerBound + upperBound).scale(0.5);

 /** Returns true if this box contains the given box. */
 bool contains(AxisAlignedBox aabb) =&gt;
     lowerBound.x &gt; aabb.lowerBound.x &amp;&amp; lowerBound.y &gt; aabb.lowerBound.y &amp;&amp;
     upperBound.y &lt; aabb.upperBound.y &amp;&amp; upperBound.x &lt; aabb.upperBound.x;

 /** Sets this box to be a copy of the given box. */
 void setFrom(AxisAlignedBox other) {
   lowerBound.copyFrom(other.lowerBound);
   upperBound.copyFrom(other.upperBound);
 }

 String toString() =&gt; "$lowerBound, $upperBound";
}
</pre>
</div>
<div>
<h3>Static Methods</h3>
<div class="method"><h4 id="testOverlap">
<button class="show-code">Code</button>
bool <strong>testOverlap</strong>(<a href="../box2d/AxisAlignedBox.html">AxisAlignedBox</a> a, <a href="../box2d/AxisAlignedBox.html">AxisAlignedBox</a> b) <a class="anchor-link" href="#testOverlap"
              title="Permalink to AxisAlignedBox.testOverlap">#</a></h4>
<div class="doc">
<p>Returns true if the given box overlaps with this box. </p>
<pre class="source">
static bool testOverlap(AxisAlignedBox a, AxisAlignedBox b) =&gt;
 !((b.lowerBound.x &gt; a.upperBound.x || b.lowerBound.y &gt; a.upperBound.y) ||
   (a.lowerBound.x &gt; b.upperBound.x || a.lowerBound.y &gt; b.upperBound.y));
</pre>
</div>
</div>
</div>
<div>
<h3>Constructors</h3>
<div class="method"><h4 id="AxisAlignedBox">
<button class="show-code">Code</button>
new <strong>AxisAlignedBox</strong>([<a href="../vector_math/vec2.html">vec2</a> lowerBound = null, <a href="../vector_math/vec2.html">vec2</a> upperBound = null]) <a class="anchor-link" href="#AxisAlignedBox"
              title="Permalink to AxisAlignedBox.AxisAlignedBox">#</a></h4>
<div class="doc">
<p>Constructs a new box with the given lower and upper bounds. If no bounds
are specified, constructs the box with both bounds at the origin.</p>
<pre class="source">
AxisAlignedBox([this.lowerBound = null, this.upperBound = null]) {
 if (lowerBound == null) lowerBound = new vec2.zero();
 if (upperBound == null) upperBound = new vec2.zero();
}
</pre>
</div>
</div>
</div>
<div>
<h3>Properties</h3>
<div class="field"><h4 id="center">
<button class="show-code">Code</button>
final <a href="../vector_math/vec2.html">vec2</a>         <strong>center</strong> <a class="anchor-link"
            href="#center"
            title="Permalink to AxisAlignedBox.center">#</a>
        </h4>
        <div class="doc">
<p>Returns the center of this box. </p>
<pre class="source">
vec2 get center =&gt; (lowerBound + upperBound).scale(0.5);
</pre>
</div>
</div>
<div class="field"><h4 id="lowerBound">
<button class="show-code">Code</button>
<a href="../vector_math/vec2.html">vec2</a>         <strong>lowerBound</strong> <a class="anchor-link"
            href="#lowerBound"
            title="Permalink to AxisAlignedBox.lowerBound">#</a>
        </h4>
        <div class="doc">
<pre class="source">
lowerBound
</pre>
</div>
</div>
<div class="field"><h4 id="upperBound">
<button class="show-code">Code</button>
<a href="../vector_math/vec2.html">vec2</a>         <strong>upperBound</strong> <a class="anchor-link"
            href="#upperBound"
            title="Permalink to AxisAlignedBox.upperBound">#</a>
        </h4>
        <div class="doc">
<pre class="source">
upperBound
</pre>
</div>
</div>
</div>
<div>
<h3>Methods</h3>
<div class="method"><h4 id="contains">
<button class="show-code">Code</button>
bool <strong>contains</strong>(<a href="../box2d/AxisAlignedBox.html">AxisAlignedBox</a> aabb) <a class="anchor-link" href="#contains"
              title="Permalink to AxisAlignedBox.contains">#</a></h4>
<div class="doc">
<p>Returns true if this box contains the given box. </p>
<pre class="source">
bool contains(AxisAlignedBox aabb) =&gt;
   lowerBound.x &gt; aabb.lowerBound.x &amp;&amp; lowerBound.y &gt; aabb.lowerBound.y &amp;&amp;
   upperBound.y &lt; aabb.upperBound.y &amp;&amp; upperBound.x &lt; aabb.upperBound.x;
</pre>
</div>
</div>
<div class="method"><h4 id="isValid">
<button class="show-code">Code</button>
bool <strong>isValid</strong>() <a class="anchor-link" href="#isValid"
              title="Permalink to AxisAlignedBox.isValid">#</a></h4>
<div class="doc">
<p>Returns true if the lower bound is strictly less than the upper bound and
both bounds are themselves valid (Vector.isValid() returns true).</p>
<pre class="source">
bool isValid() =&gt; !lowerBound.isInfinite &amp;&amp; !upperBound.isInfinite &amp;&amp;
                 !lowerBound.isNaN &amp;&amp; !upperBound.isNaN &amp;&amp;
                 lowerBound.x &lt; upperBound.x &amp;&amp; lowerBound.y &lt; upperBound.y;
</pre>
</div>
</div>
<div class="method"><h4 id="setBounds">
<button class="show-code">Code</button>
<a href="../box2d/AxisAlignedBox.html">AxisAlignedBox</a> <strong>setBounds</strong>(<a href="../vector_math/vec2.html">vec2</a> lower, <a href="../vector_math/vec2.html">vec2</a> upper) <a class="anchor-link" href="#setBounds"
              title="Permalink to AxisAlignedBox.setBounds">#</a></h4>
<div class="doc">
<p>Sets the bounds to the given values. </p>
<pre class="source">
AxisAlignedBox setBounds(vec2 lower, vec2 upper) {
 lowerBound.copyFrom(lower);
 upperBound.copyFrom(upper);
 return this;
}
</pre>
</div>
</div>
<div class="method"><h4 id="setFrom">
<button class="show-code">Code</button>
void <strong>setFrom</strong>(<a href="../box2d/AxisAlignedBox.html">AxisAlignedBox</a> other) <a class="anchor-link" href="#setFrom"
              title="Permalink to AxisAlignedBox.setFrom">#</a></h4>
<div class="doc">
<p>Sets this box to be a copy of the given box. </p>
<pre class="source">
void setFrom(AxisAlignedBox other) {
 lowerBound.copyFrom(other.lowerBound);
 upperBound.copyFrom(other.upperBound);
}
</pre>
</div>
</div>
<div class="method"><h4 id="setFromCombination">
<button class="show-code">Code</button>
void <strong>setFromCombination</strong>(<a href="../box2d/AxisAlignedBox.html">AxisAlignedBox</a> boxOne, <a href="../box2d/AxisAlignedBox.html">AxisAlignedBox</a> boxTwo) <a class="anchor-link" href="#setFromCombination"
              title="Permalink to AxisAlignedBox.setFromCombination">#</a></h4>
<div class="doc">
<p>Sets this box to be a combination of the two given boxes.
The combination is determined by picking and choosing the lowest x and y
values from the lowerBounds to form a new lower bound and picking and
choosing the largest x and y values from the upperBounds to form a new
upperBound.</p>
<pre class="source">
void setFromCombination(AxisAlignedBox boxOne, AxisAlignedBox boxTwo) {
 lowerBound.x = math.min(boxOne.lowerBound.x, boxTwo.lowerBound.x);
 lowerBound.y = math.min(boxOne.lowerBound.y, boxTwo.lowerBound.y);
 upperBound.x = math.max(boxOne.upperBound.x, boxTwo.upperBound.x);
 upperBound.y = math.max(boxOne.upperBound.y, boxTwo.upperBound.y);
}
</pre>
</div>
</div>
<div class="method"><h4 id="toString">
<button class="show-code">Code</button>
String <strong>toString</strong>() <a class="anchor-link" href="#toString"
              title="Permalink to AxisAlignedBox.toString">#</a></h4>
<div class="doc">
<div class="inherited">
<p>Returns a string representation of this object.</p>
<div class="docs-inherited-from">docs inherited from Object </div></div>
<pre class="source">
String toString() =&gt; "$lowerBound, $upperBound";
</pre>
</div>
</div>
</div>
        </div>
        <div class="clear"></div>
        </div>
        <div class="footer">
          
        </div>
        <script async src="../client-live-nav.js"></script>
        </body></html>
        
